package com.controller;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pojo.Student;
import com.service.StudentService;

@Controller
@RequestMapping("")

public class StudentController {
	
	@Autowired
	StudentService studentService;

	@RequestMapping("listStudent")
	@ResponseBody
	public Object listCategory(){
	
		ModelAndView mav = new ModelAndView();
		List<Student> cs= studentService.list();

		return cs;
	}
	
	@RequestMapping("editStudent")
	public ModelAndView editStudent(Student s){
		ModelAndView mav = new ModelAndView("editStudent");
		mav.addObject("s", s);
		return mav;
	}
	
	@RequestMapping("updateStudent")
	public ModelAndView updateStudent(Student s){
		studentService.update(s);
		ModelAndView mav = new ModelAndView("redirect:/listStudent");
		return mav;
	}
	
	
	@RequestMapping("deleteStudent")
	public ModelAndView deleteStudent(Student s){
		studentService.delete(s);
		ModelAndView mav = new ModelAndView("redirect:/listStudent");
		return mav;
	}
	
	@RequestMapping("addStudent")
	@ResponseBody
	public 	String addStudent(Student s){
		studentService.add(s);
		return "ok";
	}	
}
